import { ipcMain } from 'electron'
import { IApp } from '../../types'

export default (row: IApp) => {
  /**
   * 检查当前窗口的大小
   */
  // ipcMain.handle('check-win-status', () => row.mainWindow.isMaximized())
  /**
   * 最小化
   */
  ipcMain.on('window-min', () => {
    if (!row.mainWindow.isDestroyed()) {
      row.mainWindow.minimize()
    }
  })
  /**
   * 最大化和还原窗口
   */
  ipcMain.on('winsize', () => {
    if (!row.mainWindow.isDestroyed()) {
      !row.mainWindow.isMaximized() ? row.mainWindow.maximize() : row.mainWindow.restore()
    }
  })

  /**
   * 关闭窗口
   */
  ipcMain.on('close-system-setting', () => {
    if (!row.mainWindow.isDestroyed()) {
      row.mainWindow?.close()
      row.mainWindow?.destroy()
    }
  })
}
